package cn.com.msui.service.manage.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.msui.dao.manage.MenuDAO;
import cn.com.msui.domain.ViewItem;
import cn.com.msui.domain.manage.Menu;
import cn.com.msui.service.manage.MenuService;

@Service("menuService")
public class MenuServiceImpl extends MenuService {

	private MenuDAO menuDAO;

	public MenuDAO getMenuDAO() {
		return menuDAO;
	}

	@Autowired
	public void setMenuDAO(MenuDAO menuDAO) {
		this.menuDAO = menuDAO;
		setDao(menuDAO);
	}

	@Override
	public List<Menu> getChildrenMenus(Menu menu) throws Exception {
		Menu menuData = new Menu();
		if (menu != null)
			menuData.setParentId(menu.getId());
		menuData.setIsUse("1");
		List<Menu> menuList = menuDAO.selectMenusByCondition(menuData);
		return menuList;
	}

	@Override
	public void addMenu(Menu menu) throws Exception {
		menuDAO.insertOneMenu(menu);
	}

	@Override
	public void modifyMenu(Menu menu) throws Exception {
		menuDAO.updateOneMenu(menu);
	}

	@Override
	public void removeMenus(String[] menuIds) throws Exception {
		menuDAO.deleteMenusById(menuIds);
	}

	@Override
	public List<Menu> getMenus(ViewItem view) throws Exception {
		Map<String, Object> conditions = getPageCondition(view);
		return menuDAO.selectMenus(conditions);
	}
}
